package com.bestv.xml.processor;

import com.bestv.database.dao.DaoFactory;
import com.bestv.database.vo.IncrSeries;
import com.bestv.xml.parser.SeriesParser;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Henry on 14-7-10.
 */
public class SeriesProcessor extends Processor {
    public SeriesProcessor() {
        super();
        xmlFilePattern = "Series_.*\\.xml";
    }

    public void process() {
        SeriesParser parser = new SeriesParser();
        List<IncrSeries> serieses = new ArrayList<IncrSeries>();
        for (File file : getFiles()) {
            IncrSeries series = parser.parse(file);
            if (series != null) {
                serieses.add(series);
                moveToDoneFolder(file);
            } else {
                moveToErrorFolder(file);
            }
        }
        DaoFactory.getIncrSeriesDao().truncate();
        DaoFactory.getIncrSeriesDao().saveBatch(serieses);
    }
}
